﻿using System;
using System.Windows;
using System.Windows.Controls;

namespace WpfGameControls
{
    public partial class MessageDialog : Window
    {
        internal MessageDialog (string message, string caption, MessageBoxButton buttons)
        {
            InitializeComponent();
            this.SizeToContent = System.Windows.SizeToContent.Height;

            this.Title = caption;
            this.messageText.Text = message;

            if (buttons == MessageBoxButton.OK)
            {
                button2.Visibility = Visibility.Hidden;
                button3.Content = "O_K";
                button3.IsDefault = true;
            }
            else if (buttons == MessageBoxButton.YesNo)
            {
                button2.Content = "_Yes";
                button3.Content = "_No";
            }
            else
                throw new NotSupportedException ("All dialog types not yet implemented");
        }


        private void button2_Click (object sender, RoutedEventArgs rArgs)
        {
            DialogResult = true;
        }


        private void Window_Loaded (object sender, RoutedEventArgs e)
        {
            if (messageText.GetLastVisibleLineIndex() == 0)
                messageText.TextAlignment = TextAlignment.Center;

            if (button2.Visibility == Visibility.Hidden)
                button3.Focus();
        }
    }
}
